package cn.practice.weibopractice.common.response;

import lombok.*;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {

    private Integer state;
    private String message;
    private Object data;


    public JsonResult(StatusCode statusCode, Object data){
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
        this.data = data;
    }

    public JsonResult(StatusCode statusCode){
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
    }

    // 成功的静态方法
    public static JsonResult success(Object data){
        return new JsonResult(StatusCode.OPERATION_SUCCESS, data);
    }

    public static JsonResult success(){
        return success(null);
    }

    // 失败的静态方法
    public static JsonResult fail(Object data){
        return new JsonResult(StatusCode.OPERATION_FAILED,data);
    }
    public static JsonResult fail(){
        return fail(null);
    }

    // 异常的静态方法
    public static JsonResult exception(Object data){
        return new JsonResult(StatusCode.OPERATION_FAILED,data);
    }
}
